package com.ioc;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class FactoryBean {

    private static Map<String,Object> map=new HashMap();
    static {

        Set<String> set=ClassUtil.getClassName("com.ioc",true);
        for (String cls:set){
            try {
            Class c = Class.forName(cls);//加载类 cls=com.ioc.Boy



            IOC ioc=(IOC)c.getAnnotation(IOC.class);
            if(ioc!=null){
                String value=ioc.value();  //得到@IOC（“得到这里的内容”)
                Object obj=c.newInstance(); //实例化，相当于new
                map.put(value,obj);
            }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static <T> T getBean(String key){
        return (T)map.get(key);
    }

}
